package GUI;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import GUI.manager.VentanaFactory;
import GUI.manager.VentanaManager;

import core.model.Lista;
import core.model.Sugerencia;

public class panelAdministradorSugerenciasOtras extends javax.swing.JPanel
		implements ActionListener, ItemListener , MouseListener{
	
	public static int codigo_sugerenciaOtra;
	private VentanaManager ventanaManager=VentanaFactory.getInstance();
	private java.util.List<Sugerencia> sugerencias=ventanaManager.getSugerenciasByCode(1);
	private DefaultTableModel modelo=new DefaultTableModel(convertirArray(sugerencias), new Object[]{"Codigo","Nick","Asunto","Descripcion","Fecha"});
	private Point punto=new Point();
	public static int codigo_sugerencia;
	public panelAdministradorSugerenciasOtras() {
		initComponents();
	}

	private void initComponents() {

		panelCentro2 = new javax.swing.JPanel();
		cTipo = new javax.swing.JComboBox();
		eTipo = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();
		eMensaje = new javax.swing.JLabel();
		eDe = new javax.swing.JLabel();
		jScrollPane3 = new javax.swing.JScrollPane();
		taMensaje = new javax.swing.JTextArea();
		eAsunto = new javax.swing.JLabel();
		bEliminar = new javax.swing.JButton();
		eDe1 = new javax.swing.JLabel();
		eAsunto1 = new javax.swing.JLabel();
		bResponder = new javax.swing.JButton();
		botonSalir = new javax.swing.JButton();
		bTitulo = new javax.swing.JButton();
		rbSugerencias = new javax.swing.JRadioButton();
		rbGestion = new javax.swing.JRadioButton();
		bAtras = new javax.swing.JButton();

		setBackground(new java.awt.Color(255, 255, 255));

		panelCentro2.setBackground(new java.awt.Color(255, 255, 255));

		cTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Productos", "Otras" }));
		cTipo.addItemListener(this);
		cTipo.setSelectedIndex(1);

		eTipo.setBackground(new java.awt.Color(255, 255, 255));
		eTipo.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eTipo.setForeground(new java.awt.Color(243, 15, 120));
		eTipo.setText("TIPO DE SUGERENCIA");

		jTable1.setModel(modelo);
		jTable1.setEnabled(true);
		jTable1.addMouseListener( this);
		jTable1.addMouseListener(new MouseAdapter() 
		   {
		      public void mouseClicked(MouseEvent e) 
		      {
		         int fila = jTable1.rowAtPoint(e.getPoint());
		         int valor=Integer.parseInt(jTable1.getValueAt(fila, 0).toString());
		         codigo_sugerenciaOtra=valor;
		         
		         
		        Sugerencia sug=ventanaManager.getSugerencia(valor);
		         
		         
		        	 eDe1.setText(sug.getNick());
			         eAsunto1.setText((sug.getAsunto()));
			         taMensaje.setText(sug.getDescripcion());	
			         
		         
		        	
		         
		         
		         
		         
		         
		      
		         
		        
		         int columna = jTable1.columnAtPoint(e.getPoint());
		         if ((fila > -1) && (columna > -1)){
		        	 
		         }
		           
		      }
		      });
		jScrollPane1.setViewportView(jTable1);

		eMensaje.setBackground(new java.awt.Color(255, 255, 255));
		eMensaje.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eMensaje.setForeground(new java.awt.Color(102, 102, 102));
		eMensaje.setText("MENSAJE");
		eMensaje.setToolTipText("");

		eDe.setBackground(new java.awt.Color(255, 255, 255));
		eDe.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eDe.setForeground(new java.awt.Color(102, 102, 102));
		eDe.setText("DE");
		eDe.setToolTipText("");

		taMensaje.setColumns(20);
		taMensaje.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		taMensaje.setForeground(new java.awt.Color(102, 102, 102));
		taMensaje.setRows(5);
		jScrollPane3.setViewportView(taMensaje);

		eAsunto.setBackground(new java.awt.Color(255, 255, 255));
		eAsunto.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		eAsunto.setForeground(new java.awt.Color(102, 102, 102));
		eAsunto.setText("ASUNTO");
		eAsunto.setToolTipText("");

		bEliminar.setBackground(new java.awt.Color(255, 255, 255));
		bEliminar.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bEliminar.setForeground(new java.awt.Color(243, 15, 120));
		bEliminar.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonEliminar.png")); // NOI18N
		bEliminar.setBorder(null); // NOI18N
		bEliminar.addActionListener(this);

		eDe1.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		eDe1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		eDe1.setText("...");

		eAsunto1.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
		eAsunto1.setText("...");

		bResponder.setBackground(new java.awt.Color(255, 255, 255));
		bResponder.setFont(new java.awt.Font("Lucida Handwriting", 1, 14)); // NOI18N
		bResponder.setForeground(new java.awt.Color(243, 15, 120));
		bResponder.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/botonResponder.png")); // NOI18N
		bResponder.setBorder(null);
		bResponder.addActionListener(this);

		org.jdesktop.layout.GroupLayout panelCentro2Layout = new org.jdesktop.layout.GroupLayout(
				panelCentro2);
		panelCentro2.setLayout(panelCentro2Layout);
		panelCentro2Layout
				.setHorizontalGroup(panelCentro2Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(panelCentro2Layout
								.createSequentialGroup()
								.add(eTipo)
								.addPreferredGap(
										org.jdesktop.layout.LayoutStyle.RELATED)
								.add(cTipo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										314,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(0, 0, Short.MAX_VALUE))
						.add(jScrollPane1)
						.add(panelCentro2Layout
								.createSequentialGroup()
								.add(panelCentro2Layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.LEADING)
										.add(panelCentro2Layout
												.createSequentialGroup()
												.add(126, 126, 126)
												.add(bResponder)
												.add(94, 94, 94).add(bEliminar))
										.add(panelCentro2Layout
												.createSequentialGroup()
												.addContainerGap()
												.add(panelCentro2Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(panelCentro2Layout
																.createSequentialGroup()
																.add(12, 12, 12)
																.add(jScrollPane3,
																		org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																		505,
																		org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
														.add(panelCentro2Layout
																.createSequentialGroup()
																.add(panelCentro2Layout
																		.createParallelGroup(
																				org.jdesktop.layout.GroupLayout.LEADING)
																		.add(eDe)
																		.add(eAsunto))
																.add(18, 18, 18)
																.add(panelCentro2Layout
																		.createParallelGroup(
																				org.jdesktop.layout.GroupLayout.LEADING)
																		.add(eDe1,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				424,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																		.add(eAsunto1,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				424,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
														.add(eMensaje))))
								.addContainerGap(150, Short.MAX_VALUE)));
		panelCentro2Layout
				.setVerticalGroup(panelCentro2Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(panelCentro2Layout
								.createSequentialGroup()
								.add(4, 4, 4)
								.add(panelCentro2Layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(cTipo,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(eTipo))
								.add(18, 18, 18)
								.add(jScrollPane1,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										87,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(18, 18, 18)
								.add(panelCentro2Layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(eDe).add(eDe1))
								.add(16, 16, 16)
								.add(panelCentro2Layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(eAsunto).add(eAsunto1))
								.add(18, 18, 18)
								.add(eMensaje)
								.addPreferredGap(
										org.jdesktop.layout.LayoutStyle.UNRELATED)
								.add(jScrollPane3,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										156,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										org.jdesktop.layout.LayoutStyle.RELATED,
										37, Short.MAX_VALUE)
								.add(panelCentro2Layout
										.createParallelGroup(
												org.jdesktop.layout.GroupLayout.BASELINE)
										.add(bEliminar,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												39,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(bResponder,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												39,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
								.addContainerGap()));

		botonSalir.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/menu-salir.png")); // NOI18N
		botonSalir.setBorderPainted(false);
		botonSalir.setBackground(new java.awt.Color(255, 255, 255));
		botonSalir.addActionListener(this);

		bTitulo.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/encabezadoMain.png"));
		bTitulo.setBorder(null);
		bTitulo.setBorderPainted(false);
		bTitulo.setBackground(new java.awt.Color(255, 255, 255));
		bTitulo.addActionListener(this);

		rbSugerencias.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		rbSugerencias.setForeground(new java.awt.Color(243, 15, 120));
		rbSugerencias.setText("SUGERENCIAS");
		rbSugerencias.setSelected(true);
		rbSugerencias.setEnabled(false);
		rbSugerencias.setBackground(new java.awt.Color(255, 255, 255));

		rbGestion.setFont(new java.awt.Font("Lucida Handwriting", 1, 13)); // NOI18N
		rbGestion.setForeground(new java.awt.Color(243, 15, 120));
		rbGestion.setText("GESTION");
		rbGestion.addItemListener(this);
		rbGestion.setBackground(new java.awt.Color(255, 255, 255));

		bAtras.setIcon(new javax.swing.ImageIcon(
				"src/GUI/resources/boton_atras.png")); // NOI18N
		bAtras.setBorder(null);
		bAtras.setBackground(new java.awt.Color(255, 255, 255));

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bAtras)
								.add(layout
										.createSequentialGroup()
										.addContainerGap()
										.add(layout
												.createParallelGroup(
														org.jdesktop.layout.GroupLayout.LEADING)
												.add(rbSugerencias)
												.add(rbGestion))))
						.add(18, 18, 18)
						.add(panelCentro2,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE))
				.add(layout
						.createSequentialGroup()
						.add(96, 96, 96)
						.add(bTitulo)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).add(botonSalir)));
		layout.setVerticalGroup(layout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout
						.createSequentialGroup()
						.add(6, 6, 6)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(bTitulo,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
										104,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
								.add(botonSalir))
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED)
						.add(layout
								.createParallelGroup(
										org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout
										.createSequentialGroup()
										.add(rbSugerencias)
										.add(18, 18, 18)
										.add(rbGestion)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED,
												402, Short.MAX_VALUE)
										.add(bAtras).add(14, 14, 14))
								.add(layout
										.createSequentialGroup()
										.add(panelCentro2,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)))));
	}
	
	
	
	public String[][] convertirArray(java.util.List<Sugerencia>sugerencias)
	{
		String [][] datos=new String [sugerencias.size()][5];
		for(int i=0;i<sugerencias.size();i++)
		{
			datos[i][0]=String.valueOf(sugerencias.get(i).getCodigo_sugerencia());
			datos[i][1]=sugerencias.get(i).getNick();
			datos[i][2]=sugerencias.get(i).getAsunto();
			datos[i][3]=sugerencias.get(i).getDescripcion();
			datos[i][4]=String.valueOf(sugerencias.get(i).getFecha());

			
		}
		return datos;
	}

	private javax.swing.JButton bAtras;
	private javax.swing.JButton bEliminar;
	private javax.swing.JButton bResponder;
	private javax.swing.JButton bTitulo;
	private javax.swing.JButton botonSalir;
	private javax.swing.JComboBox cTipo;
	private javax.swing.JLabel eAsunto;
	private javax.swing.JLabel eAsunto1;
	private javax.swing.JLabel eDe;
	private javax.swing.JLabel eDe1;
	private javax.swing.JLabel eMensaje;
	private javax.swing.JLabel eTipo;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JTable jTable1;
	private javax.swing.JPanel panelCentro2;
	private javax.swing.JRadioButton rbGestion;
	private javax.swing.JRadioButton rbSugerencias;
	private javax.swing.JTextArea taMensaje;
	private JFrame actual;
	private JPanel estePanel = this;

	public void itemStateChanged(ItemEvent e) {
		if (e.getSource() == cTipo) {

			if (cTipo.getSelectedItem().equals("Productos")) {
				actual = (JFrame) UtilidadesGUI
						.getContenedorPrincipal(estePanel);
				actual.getContentPane().remove(0);
				actual.getContentPane()
						.add(new panelAdministradorSugerencias());
				actual.setPreferredSize(new Dimension(850, 630));
				actual.pack();
				actual.repaint();
				UtilidadesGUI.CentrarPantalla(actual);

			}

		}
		if (e.getSource() == rbGestion) {

			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(
					new panelAdministradorGestionProductos());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);
		}

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == bResponder) {

			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(
					new panelAdministradorResponderSugerencia());
			actual.setPreferredSize(new Dimension(680, 500));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);
		}
		if (e.getSource() == botonSalir) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelSalir(23));
			actual.setPreferredSize(new Dimension(610, 330));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bTitulo) {
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAdministradorPrincipal());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);

		}
		if (e.getSource() == bEliminar) {
			
			System.out.println("CODIGO= " + codigo_sugerencia);
			
			ventanaManager.deleteSugerencia(codigo_sugerenciaOtra);
			modelo=new DefaultTableModel(convertirArray(sugerencias), new Object[]{"Codigo","Autor","Titulo","Fecha"});
			jTable1.setModel(modelo);
			jTable1.updateUI();
			
			actual = (JFrame) UtilidadesGUI.getContenedorPrincipal(estePanel);
			actual.getContentPane().remove(0);
			actual.getContentPane().add(new panelAdministradorSugerenciasOtras());
			actual.setPreferredSize(new Dimension(850, 630));
			actual.pack();
			actual.repaint();
			UtilidadesGUI.CentrarPantalla(actual);
		}

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

}
